home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- $searchurl = "http://search";
- #
- # Build HTML index recursively
- #
- # &build_descr(<directory>,<Title>[,"index"])
- # - builds HTML index in given <directory>, top page has title <Title>.
- # if third argument is given as "index", glimpseindex is called to build
- # word index in this directory
- #
- # Uses files:
- # $TEMPLATE - HTML index template
- # do_bd - indexing program
- # put_segment - auxilary program
- #
-
- # where your HTTPD stuff is located
- $HTTPD_HOME="/r/don/usr1/paul/httpd";
-
- # Location of glimpse and glimpseindex, options for glimpseindex
- $GLIMPSE_LOC="/usr/paul/bin/glimpse";
- $GLIMPSEIDX_LOC="/usr/paul/bin/glimpseindex";
-
- # server administrator name
- $adminname = "Paul Klark";
- # server administrator e-mail
- $adminaddress = "paul@cs.arizona.edu";
-
- # index template
- $TEMPLATE="$HTTPD_HOME/wwwlib/template.bd";
- $DESCFILE=".description";
- # name of the index file
- $HTMLINDEX="ghindex.html";
-
- &build_descr("/r/don/usr1/udi/archive","Test title");
- #
- # no configuration is needed below this line
- #
- sub build_descr {
- local($dir,$toptitle,$doindex) = @_;
- chdir $dir || die "Cannot chdir to $dir to build indices: $!\n";
- open(TEMPLATE,$TEMPLATE) || die "Cannot open index template file ".
- "$TEMPLATE: $!\n";
- $outid = "FILE000";
- &do_bd("",$toptitle);
- close(TEMPLATE);
- if ($doindex) {
- # unlink <.glimpse_[^i]*>;
- system("exec $GLIMPSEIDX_LOC $GLIMPSEIDX_OPT -H . . &");
- }
- }
-
- sub do_bd {
- local($relpath,$title) = @_;
- local($file,$thisdir,$desc,$dirfiles,$dirsize,$totfiles,$totsize);
- local(%desc,$header,$OUT,$DIR,$fileshere,$dirshere);
- $totfiles = 0;
- $totsize = 0;
- $thisdir = `pwd`;
- chop $thisdir;
- undef $dirshere;
- undef $fileshere;
-
- $OUT = $outid;
- $DIR = $outid;
- $outid++;
- open($OUT,">$HTMLINDEX") || die "Cannot open file ".
- "$thisdir/$HTMLINDEX for writing: $!\n";
- print $OUT "<HEAD><TITLE>$title</TITLE></HEAD>\n";
- print $OUT "<BODY><H1>$title</H1>\n";
- &put_segment($OUT,"PROLOG");
- # slurp description file into array desc
- if (open(DESC,$DESCFILE)) {
- desc: while (<DESC>) {
- # print verbatim any lines beginning with @
- if (s/^@//) {
- print;
- next desc;
- }
- chop;
- ($file,$desc) = split(/\t+/);
- next desc unless $file =~ /^\w/;
- $desc{$file} = $desc;
- }
- close(DESC);
- }
- opendir($DIR,".");
- file: while ($file=readdir($DIR)) {
- next if $file =~ /^\./;
- next if $file eq $HTMLINDEX;
- local($dev,$ino,$mode,$nlinsk,$uid,$gid,$rdev,$size) =
- stat($file);
- if (-d $file) {
- print "subdirectory $file\n";
- chdir $file || next file;
- $desc = $desc{$file};
- if ($desc) {
- $header = $desc;
- ($dirfiles,$dirsize) =
- &do_bd("$relpath/$file",$desc);
- } else {
- # no description - make it up
- $desc = "$title/$file";
- ($dirfiles,$dirsize) =
- &do_bd("$relpath/$file",$desc);
- $header = "Directory '$file' (";
- $header .= "$dirfiles files, " if $dirfiles;
- $header .= "total $dirsize bytes)";
- }
- $totfiles += $dirfiles;
- $totsize += $dirsize;
- chdir $thisdir;
- $dirshere = "<li><a href=\"".
- "$file/$HTMLINDEX\">$header</a>\n";
- } else {
- $totfiles += 1;
- $totsize += $size;
- $header = $desc{$file};
- $header = "$file ($size bytes)" unless $header;
- $fileshere .= "<li><a href=\"$file\">".
- "$header</a>\n";
- }
- }
- closedir($DIR);
- if ($dirshere) {
- &put_segment($OUT,"PREDIR");
- print $OUT $dirshere;
- &put_segment($OUT,"POSTDIR");
- }
- &put_segment($OUT,"FORM");
- if ($fileshere) {
- &put_segment($OUT,"PREFILE");
- print $OUT $fileshere;
- &put_segment($OUT,"POSTFILE");
- }
- &put_segment($OUT,"EPILOG");
- close($OUT);
- return ($totfiles+1,$totsize);
- }
-
- sub put_segment {
- local($OUT,$label) = @_;
- local($_,$flag);
- seek(TEMPLATE,0,0);
- $flag = 0;
- line: while (<TEMPLATE>) {
- next if /^#/;
- if (/^@$label/) {
- $flag = 1;
- next line;
- }
- last line if $flag && /^@/;
- next line unless $flag;
- s/\$\w[\w_]*/$&/gee;
- print $OUT $_;
- }
- }
-